/**
 * Created by Eoly on 2016/12/31.
 */
function ObjectCanvas(canvas) {

    this.canvas = canvas;
    this.ctx = this.canvas.getContext("2d");
    this.objs = [];

    //需外部设置
    this.allObj = null;

    this.init = function () {
        var parent = this.canvas.parentNode;
        var width = parent.offsetWidth;
        var height = parent.offsetHeight;
        console.log(width);
        this.canvas.width = width;
        this.canvas.height = height;
    };
    this.init();

    this.clearAll = function () {
        this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
    };

    this.drawAll = function () {

        this.clearAll();
        for(var w in this.objs){
            if(this.objs[w].isDestroied)
                this.objs.splice(w,1);
        }
        for (var i in this.objs) {
            if(this.objs[i].needToDraw)
                this.objs[i].draw();
        }
    };

    this.startDraw = function () {
        var _this = this;
        for (var i in this.objs) {
            if(this.objs[i].needToDraw)
                this.objs[i].runWithTrack();
        }
        this.drawAll();
        requestAnimationFrame(function () {
            _this.startDraw();
        });
    };

    this.startCheckStrike = function () {
        var _this = this;
        allObj.checkStrike();
        requestAnimationFrame(function () {
            _this.startCheckStrike();
        });
    };

}